rm(list=ls()) 
getwd()
setwd("pathway/Leader_Images") # update this to direct to wherever the "Leader_Images" folder is stored

install.packages('readxl')
library(readxl)

#Bring in the complexion ratings
Complexion_Ratings <- read_excel("pathway/Complexion_Ratings.xls") # update this to direct to wherever "Complexion_Ratings.xls" is stored 

#Delete the redundant rows where there is the same leader#
complexion_trim <- Complexion_Ratings[-c(2, 3, 5, 6, 7, 9, 10, 11, 14, 16, 18, 
                                         21,22, 25, 28, 30, 32, 33, 34, 36, 37,
                                         41, 45, 47, 49, 51, 54, 57, 59, 61, 62, 63,
                                         65, 66, 69, 71, 74, 76, 80, 82, 83, 86, 88), ]

install.packages("dplyr")
library(dplyr)

complextrim_descend <- complexion_trim %>% arrange(desc(Country_Year))

#rename the different country_years so they align with the leaders and the years with those leaders#
complextrim_descend$Country_Year[complextrim_descend$Country_Year=="Venezuela 2010"] <- "Venezuela 2010, 2012"
complextrim_descend$Country_Year[complextrim_descend$Country_Year=="Venezuela 2014"] <- "Venezuela 2014, 2016"
complextrim_descend$Country_Year[complextrim_descend$Country_Year=="Uruguay 2010"] <- "Uruguay 2010, 2012, 2014"
complextrim_descend$Country_Year[complextrim_descend$Country_Year=="Trinidad & Tobago 2012"] <- "Trinidad & Tobago 2012, 2014"
complextrim_descend$Country_Year[complextrim_descend$Country_Year=="Peru 2012"] <- "Peru 2012, 2014"
complextrim_descend$Country_Year[complextrim_descend$Country_Year=="Paraguay 2010"] <- "Paraguay 2010, 2012"
complextrim_descend$Country_Year[complextrim_descend$Country_Year=="Paraguay 2014"] <- "Paraguay 2014, 2016"
complextrim_descend$Country_Year[complextrim_descend$Country_Year=="Panama 2010"] <- "Panama 2010, 2012, 2014"
complextrim_descend$Country_Year[complextrim_descend$Country_Year=="Nicaragua 2010"] <- "Nicaragua 2010, 2012, 2014, 2016"
complextrim_descend$Country_Year[complextrim_descend$Country_Year=="Mexico 2010"] <- "Mexico 2010, 2012"
complextrim_descend$Country_Year[complextrim_descend$Country_Year=="Mexico 2014"] <- "Mexico 2014, 2017"
complextrim_descend$Country_Year[complextrim_descend$Country_Year=="Jamaica 2012"] <- "Jamaica 2012, 2014"
complextrim_descend$Country_Year[complextrim_descend$Country_Year=="Honduras 2010"] <- "Honduras 2010, 2012"
complextrim_descend$Country_Year[complextrim_descend$Country_Year=="Honduras 2014"] <- "Honduras 2014, 2016"
complextrim_descend$Country_Year[complextrim_descend$Country_Year=="Haiti 2012"] <- "Haiti 2012, 2014"
complextrim_descend$Country_Year[complextrim_descend$Country_Year=="Guyana 2012"] <- "Guyana 2012, 2014"
complextrim_descend$Country_Year[complextrim_descend$Country_Year=="Guatemala 2012"] <- "Guatemala 2012, 2014"
complextrim_descend$Country_Year[complextrim_descend$Country_Year=="El Salvador 2010"] <- "El Salvador 2010, 2012, 2014"
complextrim_descend$Country_Year[complextrim_descend$Country_Year=="Ecuador 2010"] <- "Ecuador 2010, 2012, 2014, 2016"
complextrim_descend$Country_Year[complextrim_descend$Country_Year=="Dominican Republic 2010"] <- "Dominican Republic 2010, 2012"
complextrim_descend$Country_Year[complextrim_descend$Country_Year=="Dominican Republic 2014"] <- "Dominican Republic 2014, 2016"
complextrim_descend$Country_Year[complextrim_descend$Country_Year=="Costa Rica 2012"] <- "Costa Rica 2012, 2014"
complextrim_descend$Country_Year[complextrim_descend$Country_Year=="Colombia 2012"] <- "Colombia 2012, 2014, 2016"
complextrim_descend$Country_Year[complextrim_descend$Country_Year=="Chile 2010"] <- "Chile 2010, 2012"
complextrim_descend$Country_Year[complextrim_descend$Country_Year=="Chile 2014"] <- "Chile 2014, 2017"
complextrim_descend$Country_Year[complextrim_descend$Country_Year=="Brazil 2012"] <- "Brazil 2012, 2014"
complextrim_descend$Country_Year[complextrim_descend$Country_Year=="Bolivia 2010"] <- "Bolivia 2010, 2012, 2014, 2017"
complextrim_descend$Country_Year[complextrim_descend$Country_Year=="Argentina 2010"] <- "Argentina 2010, 2012, 2014"


lite.dark <- complextrim_descend %>% arrange(desc(Rating)) #arrange by light skin color to dark

install.packages('jpeg')
library(jpeg)

#Argentina#
christina1 <- readJPEG("christina1.jpg") #added
christina2 <- readJPEG("christina2.jpg") #added 
macri1 <- readJPEG("macri1.jpg") #added 
macri2 <- readJPEG("macri2.jpg") #added

# Bolivia #
evo1 <- readJPEG("evo1.jpg") #added
evo2 <- readJPEG("evo2.jpg") #added
#Brazil#
lula1 <- readJPEG("lula1.jpg") #added
lula2 <- readJPEG("lula2.jpg") #added
dilma1 <- readJPEG("dilma1.jpg") #aded
dilma2 <- readJPEG("dilma2.jpg") #added
#Chile#
bachelet1 <- readJPEG("bachelet1.jpg") #added 
bachelet2 <- readJPEG("bachelet2.jpg") #added
pinera1 <- readJPEG("pinera1.jpg") #added
pinera2 <- readJPEG("pinera2.jpg") #added
#Colombia#
uribe1 <- readJPEG("uribe1.jpg") #added
uribe2 <- readJPEG("uribe2.jpg") #added
santos1 <- readJPEG("santos1.jpg") #added
santos2 <- readJPEG("santos2.jpg") #added
#Costa Rica#
arias1 <- readJPEG("arias1.jpg") #added
arias2 <- readJPEG("arias2.jpg") #added
chinchilla1 <- readJPEG("chinchilla1.jpg") #added 
chinchilla2 <- readJPEG("chinchilla2.jpg") #added
solis1 <- readJPEG("solis1.jpg")
solis2 <- readJPEG("solis2.jpg")
#Dominican Republic#
fernandez1 <- readJPEG("fernandez1.jpg") #added
fernandez2 <- readJPEG("fernandez2.jpg") #added
medina1 <- readJPEG("medina1.jpg") #added
medina2 <- readJPEG("medina2.jpg") #added
#Ecuador#
correa1 <- readJPEG("correa1.jpg") #added
correa2 <- readJPEG("correa2.jpg") #added
#El Salvador# 
funes1 <- readJPEG("funes1.jpg") #added
funes2 <- readJPEG("funes2.jpg") #added
sanchez1 <- readJPEG("sanchez1.jpg") #added
sanchez2 <- readJPEG("sanchez2.jpg") #added
#Guatemala#
colom1 <- readJPEG("colom1.jpg") #added
colom2 <- readJPEG("colom2.jpg") #added
molina1 <- readJPEG("molina1.jpg") #added
molina2 <- readJPEG("molina2.jpg") #added
morales1 <- readJPEG("morales1.jpg") #added 
morales2 <- readJPEG("morales2.jpg") #added
#Guyana#
jagdeo1 <- readJPEG("jagdeo1.jpg")
jagdeo2 <- readJPEG("jagdeo2.jpg")
ramotar1 <- readJPEG("ramotar1.jpg") #added
ramotar2 <- readJPEG("ramotar2.jpg") #added
#Haiti#
martelly1 <- readJPEG("martelly1.jpg") #added
martelly2 <- readJPEG("martelly2.jpg") #added
#Honduras#
sosa1 <- readJPEG("sosa1.jpg")
sosa2 <- readJPEG("sosa2.jpg")
hernandez1 <- readJPEG("hernandez1.jpg") #added
hernandez2 <- readJPEG("hernandez2.jpg") #added

#Jamaica#
golding1 <- readJPEG("golding1.jpg") #added
golding2 <- readJPEG("golding2.jpg") #added
simpsonmiller1 <- readJPEG("simpsonmiller1.jpg") #added
simpsonmiller2 <- readJPEG("simpsonmiller2.jpg") #added
holness1 <- readJPEG("holness1.jpg") #added
holness2 <- readJPEG("holness2.jpg") #added

#Mexico#
calderon1 <- readJPEG("calderon1.jpg") #added
calderon2 <- readJPEG("calderon2.jpg") #added
nieto1 <- readJPEG("nieto1.jpg") #added 
nieto2 <- readJPEG("nieto2.jpg") #added

#Nicaragua#
ortega1 <- readJPEG("ortega1.jpg") #added
ortega2 <- readJPEG("ortega2.jpg") #added 

#Panama#
martinelli1 <- readJPEG("martinelli1.jpg") #added 
martinelli2 <- readJPEG("martinelli2.jpg") #added
varela1 <- readJPEG("varela1.jpg")  #added
varela2 <- readJPEG("varela2.jpg") #added

#Paraguay#
lugo1 <- readJPEG("lugo1.jpg")
lugo2 <- readJPEG("lugo2.jpg")
cartes1 <- readJPEG("cartes1.jpg") #added 
cartes2 <- readJPEG("cartes2.jpg") #added
#Peru#
garcia1 <- readJPEG("garcia1.jpg") #added 
garcia2 <- readJPEG("garcia2.jpg") #added
humala1 <- readJPEG("humala1.jpg")
humala2 <- readJPEG("humala2.jpg")
kuczynski1 <- readJPEG ("kuczynski1.jpg") #added
kuczynski2 <- readJPEG ("kuczynski2.jpg") #added

#Suriname#
bouterse1 <- readJPEG ("bouterse1.jpg") #added
bouterse2 <- readJPEG ("bouterse2.jpg") #added

#Trinidad & Tobago#
manning1 <- readJPEG ("manning1.jpg") #added
manning2 <- readJPEG ("manning2.jpg") #added
persadbissessar1 <- readJPEG ("persadbissessar1.jpg") #added
persadbissessar2 <- readJPEG ("persadbissessar2.jpg") #added


#Uruguay#
mujica1 <- readJPEG ("mujica1.jpg") #added
mujica2 <- readJPEG ("mujica2.jpg") #added
vazquez1 <- readJPEG ("vazquez1.jpg") #added 
vazquez2 <- readJPEG ("vazquez2.jpg") #added

#Venezuela#
chavez1 <- readJPEG ("chavez1.jpg") #added 
chavez2 <- readJPEG ("chavez2.jpg") #added
maduro1 <- readJPEG ("maduro1.jpg") #added
maduro2 <- readJPEG ("maduro2.jpg") #added

#create a dotchart using dotchart() 



dotchart(lite.dark$Rating,labels=lite.dark$Country_Year,cex=.39, bg="black", pch = 21,
         main="", xlab = "Leader Skin Tone Rating", cex.lab = 1.3, xlim=c(1, 9.65))
#add a vertical line to seperate and leave space for pictures#
abline(v = 9.1, col="black", lwd=1, lty=1)
par(mar=c(2.2,4.1,1,1)) #mar – A numeric vector of length 4,
#which sets the margin sizes in the following order: 
#bottom, left, top, and right. The default is
#c(5.1, 4.1, 4.1, 2.1).


rasterImage(martinelli1,9.17,44.68,9.43,45.43) #enlarged#
rasterImage(martinelli2,9.64,44.68,9.87,45.42) #enlarged
rasterImage(varela1,9.17,43.68,9.43,44.43) #enlarged
rasterImage(varela2,9.65,43.7,9.85,44.4) 
rasterImage(kuczynski1,9.17,42.67,9.43,43.43) #enlarged#
rasterImage(kuczynski2,9.65,42.7,9.85,43.4) 
rasterImage(cartes1,9.2,41.7,9.4,42.4) 
rasterImage(cartes2,9.65,41.7,9.85,42.4) 
rasterImage(vazquez1,9.2,40.7,9.4,41.4)
rasterImage(vazquez2,9.65,40.7,9.85,41.4)
rasterImage(pinera1,9.17,39.67,9.43,40.43)  #enlarged#
rasterImage(pinera2,9.62,39.4,9.88,40.6) #enlarged#
rasterImage(bachelet1,9.2,38.7,9.4,39.4)
rasterImage(bachelet2,9.65,38.7,9.85,39.4)
rasterImage(mujica1,9.17,37.67,9.43,38.44) #enlarged#
rasterImage(mujica2,9.65,37.7,9.85,38.4)
rasterImage(calderon1,9.18,36.67,9.44,37.44) #enlarged#
rasterImage(calderon2,9.62,36.67,9.88,37.43) #enlarged#
rasterImage(garcia1,9.2,35.7,9.4,36.4) 
rasterImage(garcia2,9.62,35.67,9.87,36.43) #enlarged#
rasterImage(santos1,9.2,34.7,9.4,35.4) 
rasterImage(santos2,9.65,34.7,9.85,35.4)
rasterImage(nieto1,9.2,33.7,9.4,34.4) 
rasterImage(nieto2,9.62,33.67,9.88,34.45) #enlarged#
rasterImage(uribe1,9.2,32.7,9.4,33.4) 
rasterImage(uribe2,9.62,32.7,9.88,33.4) #enlarged#
rasterImage(colom1,9.2,31.7,9.4,32.4) 
rasterImage(colom2,9.65,31.7,9.85,32.4)
rasterImage(christina1,9.2,30.65,9.4,31.45) #enlarged#
rasterImage(christina2,9.65,30.7,9.85,31.4)
rasterImage(macri1,9.2,29.7,9.4,30.4)
rasterImage(macri2,9.65,29.7,9.85,30.4)
rasterImage(sanchez1,9.2,28.7,9.4,29.4) 
rasterImage(sanchez2,9.65,28.7,9.85,29.4)
rasterImage(hernandez1,9.18,27.69,9.43,28.43) #enlarged#
rasterImage(hernandez2,9.65,27.7,9.85,28.4)
rasterImage(chinchilla1,9.2,26.7,9.4,27.4) 
rasterImage(chinchilla2,9.65,26.7,9.85,27.4)
rasterImage(arias1,9.2,25.7,9.4,26.4) 
rasterImage(arias2,9.65,25.7,9.85,26.4)
rasterImage(dilma1,9.2,24.7,9.4,25.4)
rasterImage(dilma2,9.65,24.7,9.85,25.4)
rasterImage(medina1,9.2,23.7,9.4,24.4) 
rasterImage(medina2,9.65,23.7,9.85,24.4)
rasterImage(persadbissessar1,9.2,22.7,9.4,23.4) 
rasterImage(persadbissessar2,9.65,22.7,9.85,23.4) 
rasterImage(funes1,9.2,21.7,9.4,22.4) 
rasterImage(funes2,9.65,21.7,9.85,22.4)
rasterImage(morales1,9.18,20.68,9.42,21.42) #enlarged
rasterImage(morales2,9.65,20.7,9.85,21.4)
rasterImage(molina1,9.2,19.7,9.4,20.4) 
rasterImage(molina2,9.65,19.7,9.85,20.4)
rasterImage(lula1,9.2,18.7,9.4,19.4)
rasterImage(lula2,9.65,18.7,9.85,19.4)
rasterImage(solis1,9.17,17.67,9.44,18.6) #enlarged#
rasterImage(solis2,9.63,17.68,9.87,18.42) #enlarged#
rasterImage(correa1,9.2,16.7,9.4,17.4) 
rasterImage(correa2,9.65,16.7,9.85,17.4)
rasterImage(ramotar1,9.18,15.68,9.42, 16.43) #enlarged#
rasterImage(ramotar2,9.63,15.67,9.88, 16.43) #enlarged#
rasterImage(golding1,9.2,14.7,9.4,15.4) 
rasterImage(golding2,9.65,14.7,9.85,15.4)
rasterImage(fernandez1,9.17,13.67,9.43,14.55) #enlarged#
rasterImage(fernandez2,9.62,13.68,9.87,14.43) #enlarged#
rasterImage(evo1,9.2,12.7,9.4,13.4)
rasterImage(evo2,9.63,12.65,9.85,13.45) #enlarged#
rasterImage(lugo1,9.2,11.7,9.4,12.4) 
rasterImage(lugo2,9.65,11.7,9.85,12.4) 
rasterImage(chavez1,9.17,10.67,9.43,11.43) #enlarged#
rasterImage(chavez2,9.62,10.67,9.87,11.44) #enlarged#
rasterImage(maduro1,9.2,9.7,9.4,10.4)
rasterImage(maduro2,9.65,9.7,9.85,10.4) 
rasterImage(humala1,9.2,8.7,9.4,9.4) 
rasterImage(humala2,9.62,8.68,9.88,9.43) #enlarged#
rasterImage(ortega1,9.2,7.7,9.4,8.4) 
rasterImage(ortega2,9.63,7.68,9.87,8.43) #enlarged#
rasterImage(sosa1,9.18,6.67,9.43,7.43) #enlarged#
rasterImage(sosa2,9.65,6.7,9.85,7.4)
rasterImage(simpsonmiller1,9.2,5.7,9.4,6.4) 
rasterImage(simpsonmiller2,9.62,5.67,9.88,6.37) #enlarged#
rasterImage(bouterse1,9.2,4.7,9.4,5.4) 
rasterImage(bouterse2,9.65,4.7,9.85,5.4) 
rasterImage(holness1,9.2,3.7,9.4,4.4) 
rasterImage(holness2,9.65,3.7,9.85,4.4)
rasterImage(martelly1,9.2,2.7,9.4,3.4) 
rasterImage(martelly2,9.65,2.7,9.85,3.4)
rasterImage(manning1,9.17,1.67,9.43,2.43) #enlarged#
rasterImage(manning2,9.65,1.7,9.85,2.4) 
rasterImage(jagdeo1,9.2,0.7,9.4,1.4) 
rasterImage(jagdeo2,9.63,0.7,9.88,1.44) #enlarged#


#Using RStudio, go to Export->Save as PDF. Then change dimensions to 6.72*5.74 using portrait mode
